package cn.gjxblog.modules.job.controller;

import cn.gjxblog.common.model.HttpResult;
import cn.gjxblog.common.model.PageInfo;
import cn.gjxblog.common.model.PageRequest;
import cn.gjxblog.modules.job.entity.ScheduleJobLogEntity;
import cn.gjxblog.modules.job.service.ScheduleJobLogService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;



/**
 * 定时任务日志
 *
 * @author guojiaxun
 * @date 2019-09-18 13:53:04
 */
@RestController
@RequestMapping("sys/schedulejoblog")
public class ScheduleJobLogController {
    @Autowired
    private ScheduleJobLogService scheduleJobLogService;

    /**
     * 列表
     */
    @PostMapping("/list")
    @ApiOperation("获取列表")
    public HttpResult<PageInfo> list(@RequestBody PageRequest pageRequest){
        PageInfo pageInfo = scheduleJobLogService.searchList(pageRequest);
        return HttpResult.ok(pageInfo);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{logId}")
    @ApiOperation("获取信息")
    public HttpResult info(@PathVariable("logId") Long logId){
		ScheduleJobLogEntity scheduleJobLog = scheduleJobLogService.getById(logId);

        return HttpResult.ok(scheduleJobLog);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("保存信息")
    public HttpResult save(@RequestBody ScheduleJobLogEntity scheduleJobLog){
		scheduleJobLogService.save(scheduleJobLog);

        return HttpResult.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("修改信息")
    public HttpResult update(@RequestBody ScheduleJobLogEntity scheduleJobLog){
		scheduleJobLogService.updateById(scheduleJobLog);

        return HttpResult.ok();
    }

    /**
     * 删除
     */
    @GetMapping("/delete")
    @ApiOperation("删除信息")
    public HttpResult delete(@RequestBody Long[] logIds){
		scheduleJobLogService.removeByIds(Arrays.asList(logIds));
        return HttpResult.ok();
    }

}
